<script lang="ts">
export default {
  name: "xt-dropdown",
};
</script>

<script setup lang="ts">
import { ElDropdown, ElDropdownMenu, ElDropdownItem } from "element-plus";
// import { ArrowDown } from "@element-plus/icons-vue";
import Typings from "../../../typings";

interface Props extends /* @vue-ignore */ Typings.Dropdown.props {
  options: Typings.Common.option[];
  alias?: Typings.Common.alias;
}

const props = withDefaults(defineProps<Props>(), {
  options: () => [],
  alias: () => ({ code: "code", name: "name" }),
});
</script>

<template>
  <el-dropdown class="xt-dropdown">
    <span class="el-dropdown-link">
      <slot>
        <span>下拉菜单</span>
        <!-- <xt-icon class="el-icon--right">
          <arrow-down />
        </xt-icon> -->
      </slot>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          v-for="{
            [props.alias['code']]: code,
            [props.alias['name']]: name,
            ...op
          } in options"
          :key="code"
          :command="code"
          v-bind="op"
        >
          {{ name }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<style lang="scss">
@use "../../../scss/xt-dropdown.scss";
</style>
